home *** CD-ROM | disk | FTP | other *** search
- /*
-
- RTG GadTools Library Demo
- based on
- RTG Library Usage - Skeleton Code
-
- This code © 1997 by Hans-Jörg and Thomas Frieden
- You may use any or all of this code in your own applications.
- Use this code at your own risk. It isn't guaranteed to do
- anything useful. Consider this a random sequence of characters
- that, by chance, can be compiled as a C program.
-
- Requires RTGMaster system to be installed on your system.
-
- */
-
- /* Generic "Include Everything"-type file */
- #include <global.h>
- #include "rtggadtools.h"
- #include "rtggadtools_protos.h"
- #include "rtggadtools_pragmas.h"
-
-
- struct RtgScreen *RtgScreen;
- struct ScreenReq *sr;
- struct RTGMasterBase *RTGMasterBase;
- struct Library *UtilityBase, *IntuitionBase;
- struct Library *GfxBase, *RTGGadToolsBase;
- struct TagItem rtag[] = {
- smr_ChunkySupport, -1,
- smr_PlanarSupport, -1,
- //smr_Buffers, 1,
- TAG_DONE, NULL
- };
-
- struct TagItem gtag[] = {
- grd_BytesPerRow, 0,
- grd_Width, 0,
- grd_Height, 0,
- grd_Depth, 0,
- grd_PixelLayout, 0,
- grd_ColorSpace, 0,
- grd_PlaneSize, 0,
- grd_BusSystem, 0,
- TAG_DONE, 0
- };
-
- struct TagItem tacks[] = {
- TAG_DONE,0
- };
-
- BOOL Planar;
- UBYTE *cbuf=NULL;
- ULONG width;
- UBYTE *sadr;
- ULONG cmap[1000];
- #define CBUF 76800
- BOOL Direct;
-
-
- UBYTE Arrow[] = {
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,255,0,0,0,
- 0,0,0,0,255,255,0,0,
- 0,255,255,255,255,255,255,0,
- 0,255,255,255,255,255,255,0,
- 0,0,0,0,255,255,0,0,
- 0,0,0,0,255,0,0,0,
- 0,0,0,0,0,0,0,0
- };
-
- UBYTE ArrowA[] = {
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,128,0,0,0,
- 0,0,0,0,128,128,0,0,
- 0,128,128,128,128,128,128,0,
- 0,128,128,128,128,128,128,0,
- 0,0,0,0,128,128,0,0,
- 0,0,0,0,128,0,0,0,
- 0,0,0,0,0,0,0,0
- };
-
-
- ULONG Arrow24[] = {
- 0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,
- 0x000000,0x000000,0x000000,0x000000,0xffffff,0x000000,0x000000,0x000000,
- 0x000000,0x000000,0x000000,0x000000,0xffffff,0xffffff,0x000000,0x000000,
- 0x000000,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0x000000,
- 0x000000,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0x000000,
- 0x000000,0x000000,0x000000,0x000000,0xffffff,0xffffff,0x000000,0x000000,
- 0x000000,0x000000,0x000000,0x000000,0xffffff,0x000000,0x000000,0x000000,
- 0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000
- };
-
- ULONG Arrow24A[] = {
- 0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,
- 0x000000,0x000000,0x000000,0x000000,0xffff00,0x000000,0x000000,0x000000,
- 0x000000,0x000000,0x000000,0x000000,0xffff00,0xffff00,0x000000,0x000000,
- 0x000000,0xffff00,0xffff00,0xffff00,0xffff00,0xffff00,0xffff00,0x000000,
- 0x000000,0xffff00,0xffff00,0xffff00,0xffff00,0xffff00,0xffff00,0x000000,
- 0x000000,0x000000,0x000000,0x000000,0xffff00,0xffff00,0x000000,0x000000,
- 0x000000,0x000000,0x000000,0x000000,0xffff00,0x000000,0x000000,0x000000,
- 0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000
- };
- APTR Anchor;
- RGGadget g1,g2,g3,g4;
- void *Font;
- struct TextAttr ta = {
- "topaz.font",
- 8, FS_NORMAL,
- FPF_ROMFONT
- };
-
- void fail(void) {
- if (RtgScreen) CloseRtgScreen(RtgScreen);
- if (RTGMasterBase) CloseLibrary((struct Library *)RTGMasterBase);
- if (UtilityBase) CloseLibrary(UtilityBase);
- if (RTGGadToolsBase) CloseLibrary(RTGGadToolsBase);
- if (cbuf) FreeVec(cbuf);
- exit(0L);
- }
- /*
- UpAction Hook
- This code will be called when we get an UpAction from gadget 2. It is
- used to toggle the state of gadget 1 (The toggle button)
- */
- __asm __saveds void UpAction(register __a0 RGGadget gadget) {
- RGGadgetState(g1, RGS_Toggle);
- RGRefreshGList(Anchor, g1, 1);
- }
-
-
- /*
- Custom HitTest
- This HitTest routine is used for the little arrow gadget. It actually
- checks to see if the mouse click we received hit one of the non-null
- parts of the image. If it did, it allows the gadget to be hit, other-
- wise rejects the click. This is especially usefull for shaped buttons.
-
-
- */
- __asm __saveds BOOL HitTest(register __a0 RGGadget gad,
- register __d0 WORD x,
- register __d1 WORD y) {
- UBYTE *p;
-
- if (x<gad->LeftEdge || x>=gad->LeftEdge+gad->Width) return FALSE;
- if (y<gad->TopEdge || y>=gad->TopEdge+gad->Height) return FALSE;
- x-=gad->LeftEdge; y-=gad->TopEdge;
-
- p=(UBYTE *)(gad->GadgetRender)+x+y*gad->Width;
- if (*p) return TRUE;
- else return FALSE;
-
- }
-
- void main(int argc, char **argv) {
- /*
- * Since this is a demo, I don't check anything at all
- * and simply assume that every open went ok... 8-)
- */
- int i,x;
- struct TagItem *tag;
- UBYTE rr, rg, rb;
- ULONG size;
- ULONG class;
- ULONG hp, lp, back, fore, text;
- struct IntuiMessage *msg;
- char str[512];
- ULONG retval;
- ULONG img, imga;
-
- /*
- For the most part the following code is taken from my code
- example for the rtgmaster library. Look into this archive for
- what the code does.
- */
-
- RTGMasterBase = (struct RTGMasterBase *)OpenLibrary((STRPTR)"rtgmaster.library", 0);
- UtilityBase = OpenLibrary((STRPTR)"utility.library", 37L);
- IntuitionBase = OpenLibrary("intuition.library", 37L);
- GfxBase = OpenLibrary("graphics.library", 37L);
- RTGGadToolsBase = OpenLibrary("rtggadtools.library", 0L);
- if (!RTGGadToolsBase) {
- printf("Error opening RTGGadTools library\n");
- fail();
- }
-
-
- sr = RtgScreenModeReq(rtag);
-
- if (sr==NULL) fail();
-
- RtgScreen = OpenRtgScreen(sr, tacks);
-
- GetRtgScreenData(RtgScreen, gtag);
-
- tag=FindTagItem(grd_BytesPerRow, gtag);
- size = tag->ti_Data;
-
- tag=FindTagItem(grd_Width, gtag);
- width = tag->ti_Data;
-
- tag=FindTagItem(grd_PixelLayout, gtag);
- printf("Screen pixel layout is ");
- switch(tag->ti_Data) {
- case grd_PLANAR: printf("planar\n"); break;
- case grd_PLANATI: printf("interleaved planar\n"); break;
- case grd_CHUNKY: printf("8-Bit Z-Ordered (chunky)\n"); break;
- case grd_HICOL15: printf("15-Bit Chunky (2 Byte/pixel)\n"); break;
- case grd_HICOL16: printf("16-Bit Chunky (2 Byte/pixel)\n"); break;
- case grd_TRUECOL24: printf("24-Bit Chunky (3 Byte/pixel)\n"); break;
- case grd_TRUECOL24P: printf("24-Bit Chunky (3 Byteplanes/pixel)\n"); break;
- case grd_TRUECOL32: printf("24-Bit Chunky (4 Bytes/pixel)\n"); break;
- case grd_GRAFFITI: printf("Graffiti 8 bit\n"); break;
- case grd_TRUECOL32B: printf("24-Bit Chunky (4 Bytes/pixel)\n"); break;
- default: printf("unknown (%d)\n", tag->ti_Data); break;
- }
-
- tag=FindTagItem(grd_ColorSpace, gtag);
- if (tag->ti_Data) {
- if (tag->ti_Data == grd_Palette) Direct=FALSE; else Direct=TRUE;
- printf("Color space is ");
- switch(tag->ti_Data) {
- case grd_Palette: printf("CLUT-Based\n"); break;
- case grd_RGB: printf("RGB (low-endian RGB)\n"); break;
- case grd_BGR: printf("BGR (high-endian RGB)\n"); break;
- default: printf("unknown (%d)\n", tag->ti_Data); break;
- }
- }
-
- tag=FindTagItem(grd_BusSystem, gtag);
- if (tag->ti_Data) {
- printf("Graphics card bus is ");
- switch(tag->ti_Data) {
- case grd_Z3: printf("Zorro III\n"); break;
- case grd_Z2: printf("Zorro II\n"); break;
- case grd_Custom: printf("default custom chips\n"); break;
- case grd_RGBPort: printf("conneted to the RGB Port\n"); break;
- case grd_GVP: printf("GVP Special Bus (EGS110)\n"); break;
- case grd_DDirect: printf("DracCo® Direct\n"); break;
- default: printf("an unknown bus system\n"); break;
- }
- }
-
- if (tag->ti_Data == grd_PLANAR) Planar = TRUE;
- else Planar = FALSE;
-
- printf("Screen is %ld x %ld x %ld\n", gtag[1].ti_Data, gtag[2].ti_Data, gtag[3].ti_Data);
- printf("It has %ld bytes per row\n", size);
-
-
- if (Planar == TRUE) {
- cbuf = AllocVec(CBUF, MEMF_CLEAR|MEMF_FAST);
- if (cbuf==NULL) {
- cbuf=AllocVec(CBUF, MEMF_CLEAR);
- if (cbuf==NULL) {
- printf("Out of memory *SIGH*\n");
- fail();
- }
- }
- }
-
- if (Direct == FALSE) {
- cmap[0] = 256 * 65536;
- rr = 0;
- rg = 0;
- rb = 0;
- x = 1;
- for (i = 0; i < 256; i++) {
- if (i==17) {
- cmap[x++] = 0xFFFFFFFF;
- cmap[x++] = 0xFFFFFFFF;
- cmap[x++] = 0xFFFFFFFF;
- } else {
- cmap[x++] = (i << 24) | 0xffffff;
- cmap[x++] = (i << 24) | 0xffffff;
- cmap[x++] = (i << 24) | 0xffffff;
- }
- }
- cmap[x++]=0;
- LockRtgScreen(RtgScreen);
- LoadRGBRtg(RtgScreen, (APTR) cmap);
- UnlockRtgScreen(RtgScreen);
- }
-
- if (RtgScreen) {
- /*
- We have to create an anchor for the gadget chain. On Intuition
- we usually have a window or Screen for this. Since there's
- no such thing in RTGMaster, we use a custom structure for this.
-
- DO NOT ALLOCATE THIS YOURSELF. Use the RGNewAnchor function.
-
- The Anchor will be on the RtgScreen, with 1 buffer, and optional
- TrueColor support.
-
- */
- Anchor = RGNewAnchor(RtgScreen, 1, Direct);
- /*
- Since the positioning stuff is only guaranteed to work with
- an 8x8 font, we set Topaz/8 on our screen.
-
- */
- Font = RtgOpenFont(RtgScreen, &ta);
- if (Font) {
- RtgSetFont(RtgScreen, Font);
- }
-
- /*
- Initialize some color values depending on the color model.
- RTGGadTools tries to handle everything, but interpretation
- of the values passed depends on the color model of the
- screen, so you have to take care of that.
- */
- if (Direct == FALSE) {
- text = 255;
- hp = 255;
- lp = 50;
- back = 40;
- fore = 80;
- } else {
- text = 0x00ff7733;
- hp = 0x00ffffff;
- lp = 0x00202020;
- back = 0x000055;
- fore = 0x00888888;
- }
-
- /*
- Create gadget 1.
- This is a toggle-select button. Since we specify a text for it,
- we can leave width/height calculation to RTGGadTools. Note that
- for each gadget, we give unique numbers for Up/Down-Actions.
- That means that we get a downaction nn for gadget n and an UpAction
- n for gadget n. See the Autodocs for details.
- */
- g1 = RGNewGadget(
- RGG_LeftEdge, 10,
- RGG_TopEdge, 10,
- RGG_RenderText, "Button 1",
- RGG_Flags, RGF_ToggleSelect,
- RGG_UpAction, 1,
- RGG_DownAction, 11,
- RGG_TextPen, text,
- RGG_HiPen, hp,
- RGG_LoPen, lp,
- RGG_BackColor, back,
- RGG_HiliteColor, fore,
- TAG_DONE);
-
- /*
- Gadget 2 will be a normal pushbutton with a custom UpAction.
- UpActions are executed when the mouse button is *released*
- on the gadget, while a DownAction will be called when the
- button is pressed.
- */
- g2 = RGNewGadget(
- RGG_LeftEdge, 40,
- RGG_TopEdge, 30,
- RGG_RenderText, "Disable/Enable 1",
- RGG_UpAction, (ULONG)UpAction,
- RGG_Flags, RGF_UpAction,
- RGG_DownAction, 22,
- RGG_TextPen, text,
- RGG_HiPen, hp,
- RGG_LoPen, lp,
- RGG_BackColor, back,
- RGG_HiliteColor, fore,
- TAG_DONE);
-
- /*
- Again, a pushbutton which quits the program.
- */
- g3 = RGNewGadget(
- RGG_LeftEdge, 10,
- RGG_TopEdge, 50,
- RGG_RenderText, "Quit",
- RGG_UpAction, 3,
- RGG_DownAction, 33,
- RGG_TextPen, text,
- RGG_HiPen, hp,
- RGG_LoPen, lp,
- RGG_BackColor, back,
- RGG_HiliteColor, fore,
- TAG_DONE);
-
- if (Direct == TRUE) {
- img = (ULONG) Arrow24;
- imga = (ULONG) Arrow24A;
- } else {
- img = (ULONG) Arrow;
- imga = (ULONG) ArrowA;
- }
-
- /*
- The Arrow-Shaped button. Since this is an image button, we
- *MUST* specify width and height. See the Autodocs and other
- documentation for the format of the image data.
- */
- g4 = RGNewGadget(
- RGG_LeftEdge, 10,
- RGG_TopEdge, 70,
- RGG_Width, 8,
- RGG_Height, 8,
- RGG_HitTest, HitTest,
- RGG_RenderImage, img,
- RGG_SelectRender, imga,
- RGG_UpAction, 4,
- RGG_DownAction, 44,
- RGG_BackColor, back,
- RGG_HiliteColor, fore,
- TAG_DONE);
-
- printf("Created four gadgets at 0x%lx, 0x%lx, 0x%lx, 0x%lx\n",
- g1,g2,g3,g4);
-
- /*
- Now add the gadgets to the Anchor. Normally, you would
- check if the creation was successfull.
- */
- RGAddGadget(Anchor, g1, 0);
- RGAddGadget(Anchor, g2, 0);
- RGAddGadget(Anchor, g3, 0);
- RGAddGadget(Anchor, g4, 0);
-
- LockRtgScreen(RtgScreen);
- sadr = (UBYTE *)GetBufAdr(RtgScreen,0);
- if (Direct) { /* Delete the screen in TrueColor Mode. */
- LONG x; /* Could have used BlitClear, too */
- for (x=0; x<gtag[2].ti_Data; x++) {
- DrawRtgLineRGB(RtgScreen,sadr,0, 0,x,gtag[1].ti_Data-1,x);
- }
- }
- RtgInitRDCMP(RtgScreen); /* Start the RDCMP */
- /*
- The following call draws the gadgets for the first time.
- You must do this once. Normally you would open the window your
- gadgets are in (with Intuition), but alas, we don't have one
- here...
- */
- RGRefreshGList(Anchor, NULL, -1);
-
- do {
- msg=RtgGetMsg(RtgScreen); /* Get the RDCMP message */
- /*
- The RGDoGadgets call handles all the stuff. You must call
- this on a regular basis (with every message you get from
- the RDCMP). NULL messages will be ignored, you could also
- have moved the "retval = ..." statement into the if statement
- below.
- */
- retval = RGDoGadgets(Anchor, msg);
- if (msg) {
- class = msg->Class;
- RtgReplyMsg(RtgScreen, msg);
- if (class == IDCMP_RAWKEY) break;
- }
- if (retval == 3) break; /* Quit button was released */
- if (retval != 0) { /* Print what happened */
- sprintf(str, "RetVal: %d ", retval);
- if (Direct) RtgSetTextModeRGB(RtgScreen, 0xffffff, 0, JAM2);
- else RtgSetTextMode(RtgScreen, 255, 0, JAM2);
- RtgText(RtgScreen, sadr, str, strlen(str), 5,100);
- }
- } while( 1);
-
- if (Font) RtgCloseFont(RtgScreen, Font);
- /*
- When you're done, dispose the anchor. This automatically
- disposes the gadgets, too, if they are still attached.
- */
- RGDisposeAnchor(Anchor);
-
-
- UnlockRtgScreen(RtgScreen);
- CloseRtgScreen(RtgScreen);
- }
-
- CloseLibrary(GfxBase);
- CloseLibrary((struct Library *)RTGMasterBase);
- CloseLibrary(UtilityBase);
- CloseLibrary(IntuitionBase);
- }
-
-